package dto

import "time"

// CreateUserTransactionRequest 创建用户交易请求
type CreateUserTransactionRequest struct {
	Chain       string  `json:"chain" binding:"required,oneof=btc eth bsc sol" validate:"required,oneof=btc eth bsc sol"`
	Symbol      string  `json:"symbol" binding:"required" validate:"required"`
	FromAddress string  `json:"from_address" binding:"omitempty" validate:"omitempty"`
	ToAddress   string  `json:"to_address" binding:"omitempty" validate:"omitempty"`
	Amount      string  `json:"amount" binding:"omitempty" validate:"omitempty"`
	Fee         string  `json:"fee" binding:"omitempty" validate:"omitempty"`
	GasLimit    *uint   `json:"gas_limit" validate:"omitempty,min=1"`
	GasPrice    *string `json:"gas_price" validate:"omitempty"`
	Nonce       *uint64 `json:"nonce" validate:"omitempty,min=0"`
	Remark      string  `json:"remark" validate:"omitempty,max=500"`

	// EIP-1559费率字段
	MaxPriorityFeePerGas *string `json:"max_priority_fee_per_gas" validate:"omitempty"`
	MaxFeePerGas         *string `json:"max_fee_per_gas" validate:"omitempty"`

	// 代币交易相关字段
	TransactionType       string `json:"transaction_type" binding:"omitempty" validate:"omitempty,oneof=coin token"`
	ContractOperationType string `json:"contract_operation_type" binding:"omitempty" validate:"omitempty,oneof=transfer approve transferFrom balanceOf"`
	TokenContractAddress  string `json:"token_contract_address" binding:"omitempty" validate:"omitempty"`
	AllowanceAddress      string `json:"allowance_address" binding:"omitempty" validate:"omitempty"`

	// BTC特有字段（可选）
	BTCVersion  *int32     `json:"btc_version" validate:"omitempty"`
	BTCLockTime *uint32    `json:"btc_lock_time" validate:"omitempty"`
	BTCTxIn     []BTCTxIn  `json:"btc_tx_in" validate:"omitempty,dive"`
	BTCTxOut    []BTCTxOut `json:"btc_tx_out" validate:"omitempty,dive"`
}

// BTCTxIn 输入
type BTCTxIn struct {
	TxID      string `json:"txid"`
	Vout      uint32 `json:"vout"`
	ScriptSig string `json:"script_sig,omitempty"`
	Sequence  uint32 `json:"sequence,omitempty"`
}

// BTCTxOut 输出
type BTCTxOut struct {
	ValueSatoshi uint64 `json:"value_satoshi"`
	ScriptPubKey string `json:"script_pub_key,omitempty"`
	Address      string `json:"address,omitempty"`
}

// UpdateUserTransactionRequest 更新用户交易请求
type UpdateUserTransactionRequest struct {
	// 基础字段更新
	FromAddress *string `json:"from_address" validate:"omitempty"`
	ToAddress   *string `json:"to_address" validate:"omitempty"`
	Amount      *string `json:"amount" validate:"omitempty"`
	Fee         *string `json:"fee" validate:"omitempty"`
	Remark      *string `json:"remark" validate:"omitempty,max=500"`

	// ETH相关字段
	GasLimit *uint   `json:"gas_limit" validate:"omitempty,min=1"`
	GasPrice *string `json:"gas_price" validate:"omitempty"`
	Nonce    *uint64 `json:"nonce" validate:"omitempty,min=0"`

	// EIP-1559费率字段
	MaxPriorityFeePerGas *string `json:"max_priority_fee_per_gas" validate:"omitempty"`
	MaxFeePerGas         *string `json:"max_fee_per_gas" validate:"omitempty"`

	// 代币交易相关字段
	TransactionType       *string `json:"transaction_type" validate:"omitempty,oneof=coin token"`
	ContractOperationType *string `json:"contract_operation_type" validate:"omitempty,oneof=transfer approve transferFrom balanceOf"`
	TokenContractAddress  *string `json:"token_contract_address" validate:"omitempty"`
	AllowanceAddress      *string `json:"allowance_address" validate:"omitempty"`

	// BTC特有字段
	BTCVersion  *int32     `json:"btc_version" validate:"omitempty"`
	BTCLockTime *uint32    `json:"btc_lock_time" validate:"omitempty"`
	BTCTxIn     []BTCTxIn  `json:"btc_tx_in" validate:"omitempty,dive"`
	BTCTxOut    []BTCTxOut `json:"btc_tx_out" validate:"omitempty,dive"`

	// 状态相关字段
	Status        *string `json:"status" validate:"omitempty,oneof=draft unsigned in_progress packed confirmed failed"`
	TxHash        *string `json:"tx_hash" validate:"omitempty"`
	UnsignedTx    *string `json:"unsigned_tx" validate:"omitempty"`
	SignedTx      *string `json:"signed_tx" validate:"omitempty"`
	BlockHeight   *uint64 `json:"block_height" validate:"omitempty"`
	Confirmations *uint   `json:"confirmations" validate:"omitempty"`
	ErrorMsg      *string `json:"error_msg" validate:"omitempty"`
}

// UserTransactionResponse 用户交易响应
type UserTransactionResponse struct {
	ID          uint    `json:"id"`
	UserID      uint64  `json:"user_id"`
	Chain       string  `json:"chain"`
	Symbol      string  `json:"symbol"`
	FromAddress string  `json:"from_address"`
	ToAddress   string  `json:"to_address"`
	Amount      string  `json:"amount"`
	Fee         string  `json:"fee"`
	GasLimit    *uint   `json:"gas_limit"`
	GasPrice    *string `json:"gas_price"`
	Nonce       *uint64 `json:"nonce"`
	Status      string  `json:"status"`

	// EIP-1559费率字段
	MaxPriorityFeePerGas *string   `json:"max_priority_fee_per_gas"`
	MaxFeePerGas         *string   `json:"max_fee_per_gas"`
	TxHash               *string   `json:"tx_hash"`
	BlockHeight          *uint64   `json:"block_height"`
	Confirmations        *uint     `json:"confirmations"`
	ErrorMsg             *string   `json:"error_msg"`
	Remark               string    `json:"remark"`
	CreatedAt            time.Time `json:"created_at"`
	UpdatedAt            time.Time `json:"updated_at"`

	// ERC-20合约操作相关字段
	TransactionType       string `json:"transaction_type,omitempty"`
	ContractOperationType string `json:"contract_operation_type,omitempty"`
	TokenContractAddress  string `json:"token_contract_address,omitempty"`
	AllowanceAddress      string `json:"allowance_address,omitempty"`
	TokenName             string `json:"token_name,omitempty"`
	TokenDecimals         *uint8 `json:"token_decimals,omitempty"`

	// QR码导出相关字段
	ChainID    *string `json:"chain_id,omitempty"`
	TxData     *string `json:"tx_data,omitempty"`
	AccessList *string `json:"access_list,omitempty"`

	// 签名组件
	V *string `json:"v,omitempty"`
	R *string `json:"r,omitempty"`
	S *string `json:"s,omitempty"`

	// BTC特有字段
	BTCVersion   *int32  `json:"btc_version,omitempty"`
	BTCLockTime  *uint32 `json:"btc_lock_time,omitempty"`
	BTCTxInJSON  *string `json:"btc_tx_in_json,omitempty"`
	BTCTxOutJSON *string `json:"btc_tx_out_json,omitempty"`
}

// UserTransactionListResponse 用户交易列表响应
type UserTransactionListResponse struct {
	Transactions []UserTransactionResponse `json:"transactions"`
	Total        int64                     `json:"total"`
	Page         int                       `json:"page"`
	PageSize     int                       `json:"page_size"`
	HasMore      bool                      `json:"has_more"`
}

// ExportTransactionRequest 导出交易请求
type ExportTransactionRequest struct {
	// EIP-1559费率设置（可选，如果不提供则使用默认值）
	MaxPriorityFeePerGas *string `json:"maxPriorityFeePerGas" validate:"omitempty"`
	MaxFeePerGas         *string `json:"maxFeePerGas" validate:"omitempty"`
}

// ExportTransactionResponse 导出交易响应
type ExportTransactionResponse struct {
	UnsignedTx  string  `json:"unsigned_tx"`
	Chain       string  `json:"chain"`
	Symbol      string  `json:"symbol"`
	FromAddress string  `json:"from_address"`
	ToAddress   string  `json:"to_address"`
	Amount      string  `json:"amount"`
	Fee         string  `json:"fee"`
	GasLimit    *uint   `json:"gas_limit"`
	GasPrice    *string `json:"gas_price"`
	Nonce       *uint64 `json:"nonce"`

	// EIP-1559费率字段
	MaxPriorityFeePerGas *string `json:"max_priority_fee_per_gas"`
	MaxFeePerGas         *string `json:"max_fee_per_gas"`

	// QR码数据
	ChainID    *string `json:"chain_id"`
	TxData     *string `json:"tx_data"`
	AccessList *string `json:"access_list"`
}

// ImportSignatureRequest 导入签名请求
type ImportSignatureRequest struct {
	ID       uint    `json:"id" binding:"required" validate:"required"`
	SignedTx string  `json:"signed_tx" binding:"required" validate:"required"`
	V        *string `json:"v,omitempty"`
	R        *string `json:"r,omitempty"`
	S        *string `json:"s,omitempty"`
}

// SendTransactionRequest 发送交易请求
type SendTransactionRequest struct {
	ID uint `json:"id" binding:"required" validate:"required"`
}

// UserTransactionStatsResponse 用户交易统计响应
type UserTransactionStatsResponse struct {
	TotalTransactions int64 `json:"total_transactions"`
	DraftCount        int64 `json:"draft_count"`
	UnsignedCount     int64 `json:"unsigned_count"`
	InProgressCount   int64 `json:"in_progress_count"`
	PackedCount       int64 `json:"packed_count"`
	ConfirmedCount    int64 `json:"confirmed_count"`
	FailedCount       int64 `json:"failed_count"`
}
